package com.itheima.controller;

import com.itheima.entity.Category;
import com.itheima.entity.Employee;
import com.itheima.jsonresult.JsonResult;
import com.itheima.service.CategoryService;
import com.itheima.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/category")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    /**
     * 新增分类
     * @param category
     * @return
     */
    @PostMapping
    public JsonResult add(@RequestBody Category category){
        return categoryService.add(category);
    }

    /**
     *编辑分类
     * @param category
     * @return
     */
    @PutMapping
    public JsonResult put(@RequestBody Category category){
        return categoryService.put(category);
    }

    /**
     * 删除分类
     * @param id
     * @return
     */
    @DeleteMapping
    public JsonResult delete(String id) {
        return categoryService.delete(id);
    }

    /**
     * 分类下拉列表
     * @return
     */
    @GetMapping("/list")
    public JsonResult categoryList(Integer type){
        return categoryService.categoryList(type);
    }

    /**
     * 分类信息分页查询
     * @param name
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("/page")
    public JsonResult getPage(String name, @RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer pageSize){
        return categoryService.getPage(name,page,pageSize);
    }





}
